﻿@using System.Net.Http
@model   EpiInfoCloudMagpiBridge.Models.DownloadResponsesHelper
@{
    ViewBag.Title = "Index";
}

<div>
    <h3>Download Responses</h3>
    <hr />
    @*@using (Html.BeginForm("Download", "DownloadResponse", FormMethod.Post))*@
    @using (Ajax.BeginForm("Download", "DownloadResponse", FormMethod.Post, new AjaxOptions
    {
        HttpMethod = "post",
        InsertionMode = InsertionMode.Replace,
        UpdateTargetId = "status"
    }))
    {
    <!-- form goes here -->
        <table cellspacing="0" cellpadding="0">
            <tr>
                <td>Survey Name</td>
                @*<td>@Html.DropDownList("SurveyName")</td>*@
                @*<td><select id="surveyList"><option></option><option></option></select></td>*@
                <td width="20"></td>
                <td>
                    <select class="form-control" id="dropdown-2" name="dropdown-2" onchange="clearResults();" style=" width 172px;">
                        @* <option value="0" selected="selected" disabled="disabled">Arrange by:</option>*@
                        @foreach (var item in Model.MagpiAzureMappingList)
                        {
                            <option value="@item.SurveyID  ">@item.SurveyName </option>
                        }

                        @*       <option value="3">Last Saved Forms First</option>*@
                    </select>

                </td>
            </tr>
            <tr height="20">
                <td></td>
                <td width="20"></td>
                <td></td>
            </tr>
            <tr>
                <td>Start Date</td>
                <td width="20"></td>
                <td>
                    @{
                        string padDay = "";
                        string padMonth = "";

                        // today
                        if (DateTime.Now.Day.ToString().Length == 1)
                        {
                            padDay = "0" + DateTime.Now.Day.ToString();
                        }
                        else
                        {
                            padDay = DateTime.Now.Day.ToString();
                        }
                        if (DateTime.Now.Month.ToString().Length == 1)
                        {
                            padMonth = "0" + DateTime.Now.Month.ToString();
                        }
                        else
                        {
                            padMonth = DateTime.Now.Month.ToString();
                        }
                        var today = DateTime.Now.Year + "-" + padMonth + "-" + padDay;

                        // yesterday
                        DateTime yesterdayDate = DateTime.Now.Subtract(new TimeSpan(1, 0, 0, 0));
                        if (yesterdayDate.Day.ToString().Length == 1)
                        {
                            padDay = "0" + yesterdayDate.Day.ToString();
                        }
                        else
                        {
                            padDay = yesterdayDate.Day.ToString();
                        }
                        if (yesterdayDate.Month.ToString().Length == 1)
                        {
                            padMonth = "0" + yesterdayDate.Month.ToString();
                        }
                        else
                        {
                            padMonth = yesterdayDate.Month.ToString();
                        }
                        var yesterday = yesterdayDate.Year + "-" + padMonth + "-" + padDay;

                        <input class="form-control" name="startDate" id="startDate" onchange="clearResults();" type="date" value="@yesterday" />
                    }
                </td>

            </tr>
            <tr height="20">
                <td></td>
                <td width="20"></td>
                <td></td>
            </tr>
            <tr>
                <td>End Date</td>
                <td width="20"></td>
                <td>
                    @{

                        <input class="form-control" name="endDate" id="endDate" onchange="clearResults();" type="date" value="@today" />
                    }
                </td>

            </tr>
        </table>
        @*<span>@(4 * 5)  </span>*@
        <br />
        <button class="btn btn-primary" submit="submit" onclick="clearResults();">Transfer</button>
        <div id="status" style="font-weight:bold; margin-top:15px; font-size: 18px"><span class="label label-success">@Html.DisplayFor(modelItem => Model.DownloadCompleteText)</span></div>
    }

</div>
@Scripts.Render("~/bundles/custom")




